package net.begincode.service;

import net.begincode.mapper.OperaLogMapper;
import net.begincode.model.OperaLog;
import net.begincode.model.OperaLogExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by saber on 2017/9/23.
 */
@Service
public class OperaLogService {

    @Resource
    private OperaLogMapper operaLogMapper;

    /**
     * 查询所有操作日志
     * @return list 服务
     */
    public List<OperaLog> listOperaLog(){
        OperaLogExample operaLogExample = new OperaLogExample();
        OperaLogExample.Criteria criteria = operaLogExample.createCriteria();
        criteria.andIdIsNotNull();
        return operaLogMapper.selectByExample(operaLogExample);
    }


    /**
     * 根据服务查询所有操作日志
     * @return list 服务
     */
    public List<OperaLog> listServerLog(Integer serverId){
        OperaLogExample operaLogExample = new OperaLogExample();
        OperaLogExample.Criteria criteria = operaLogExample.createCriteria();
        criteria.andServerIdEqualTo(serverId);
        return operaLogMapper.selectByExample(operaLogExample);
    }

    /**
     * 根据服务键值查询所有操作日志
     * @return list 服务
     */
    public List<OperaLog> listKeyAndServerLog(Integer serverId ,String key){
        OperaLogExample operaLogExample = new OperaLogExample();
        OperaLogExample.Criteria criteria = operaLogExample.createCriteria();
        criteria.andServerIdEqualTo(serverId).andKeyEqualTo(key);
        return operaLogMapper.selectByExample(operaLogExample);
    }

    /**
     * 根据服务键值查询所有操作日志
     * @return list 服务
     */
    public Integer insertOperaLogLog(OperaLog operaLog){
        return operaLogMapper.insertSelective(operaLog);
    }



}
